/**
 * @apiDefine ErrorResponse
 * @apiError (请求错误) {String} err_message 错误信息描述
 */

/**
 * @apiVersion 1.0.0
 * @apiGroup  运费
 * @api {POST} api/updatefreight 更新运费
 * @apiName api/updatefreight
 * @apiExample {js} axios 例子:
 *  axios.post('http://39.105.38.34:8080/api/updatefreight', {
 *    id: 运费id,
 *    province: 省份,
 *    city: 城市,
 *    freight: 运费,
 *    storeid: 店铺id,
 *  });
 * @apiHeader {String} authorization 用户登录或注册成功时返回的 token
 * @apiParam {Number} id 运费id
 * @apiParam {String} province 省份
 * @apiParam {String} city 城市
 * @apiParam {Number} freight 运费
 * @apiParam {Number} storeid 店铺id
 * @apiSuccess (请求成功) {Object} freight 运费数据
 * @apiuse  ErrorResponse
 */


const { query, create, update } = require('../../helper/db');
const { ok, door } = require('../../helper/util');

module.exports = async ctx => {
  var params = ctx.request.body;
  var token = ctx.headers.authorization;
  var user = await door(token);
  var freight = await update('freight', {
    id: params.id,
    province: params.province,
    city: params.city,
    freight: params.freight,
    storeid: params.storeid,
  });

  ctx.body = ok({ freight });
}